package com.zzxy.spring12.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect

public class MyAspectJ {

    @Pointcut("execution(* com.zzxy.spring12.service.impl.*.*(..))")
    public void myPointcut(){

    }
//    <aop:before method="myBefore" pointcut-ref="myPointcut"/>
    @Before("myPointcut()")
    public void myBefore(JoinPoint jp) {
        System.out.println("before  mehtod " + jp.getSignature().getName());
        System.out.println("before ...");
    }

    @AfterReturning(value = "myPointcut()" , returning = "ret")
    public void myAfterReturning(JoinPoint jp,Object ret){
        System.out.println("after returning .."+ ret);
    }

    @Around("myPointcut()")
    public Object myAround(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around before..");
        Object obj = pjp.proceed();
        System.out.println("around after..");
        return obj;
    }

    @AfterThrowing(value = "myPointcut()", throwing = "e")
    public void myThrowable(JoinPoint jo, Throwable e){
        System.out.println("throwing .." + e.getMessage());
        //write to log
    }
    @After("myPointcut()")
    public void myAfter(JoinPoint jp) {
        System.out.println(jp.getSignature().getName());
        System.out.println("after ...");
    }
}
